package com.zhangshujie.ShoppingSystem;
import java.util.HashMap;
import java.util.Map;

public class ShoppingCartManager {
    public void checkout(ShoppingCart cart, String paymentMethod) {
        double totalAmount = cart.calculateTotal();
        if (totalAmount > 0) {
            // 模拟支付逻辑
            System.out.println("支付成功！支付方式: " + paymentMethod + "，总金额: " + totalAmount);
            cart.clear();
        } else {
            System.out.println("购物车为空，无法结账！");
        }
    }

    public void viewCart(ShoppingCart cart) {
        if (cart.getItems().isEmpty()) {
            System.out.println("购物车为空！");
        } else {
            System.out.println("购物车内容：");
            for (Map.Entry<Product, Integer> entry : cart.getItems().entrySet()) {
                Product product = entry.getKey();
                int quantity = entry.getValue();
                System.out.println(product.getName() + " - 数量: " + quantity + " - 单价: " + product.getRetailPrice());
            }
        }
    }

    public void addProductToCart(ShoppingCart cart, Product product, int quantity) {
        cart.addProduct(product, quantity);
        System.out.println("商品 " + product.getName() + " 已加入购物车，数量: " + quantity);
    }

    public void removeProductFromCart(ShoppingCart cart, Product product) {
        cart.removeProduct(product);
        System.out.println("商品 " + product.getName() + " 已从购物车移除！");
    }

    public void updateProductQuantityInCart(ShoppingCart cart, Product product, int quantity) {
        cart.updateProductQuantity(product, quantity);
        System.out.println("商品 " + product.getName() + " 的数量已更新为: " + quantity);
    }
}

